<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>

</body>
<script>
	{
		// 求交集
		// let arr1 = [1,2,3,4,5,6,5,4,3,2,1];
		// let arr2 = [4,5,6,7,8,9,8,7,6,5,4];
		// 实现：
		// let result = arr1.filter(function(item){
		// 	return arr2.includes(item);
		// })
		// // console.log(result);// [4,5,6,5,4]
		// console.log(new Set(result));// [4,5,6]
		
		// 优化：先去重，再求交集
		// console.log([...new Set(arr1)]);// [1,2,3,4,5,6]
		// let s1 = new Set(arr2);
		// let result = [...new Set(arr1)].filter(item=>s1.has(item));
		// console.log(result);
	}
	{
		// 求并集
		// let arr1 = [1,2,3,4,5,6,5,4,3,2,1];
		// let arr2 = [4,5,6,7,8,9,8,7,6,5,4];
		// console.log(new Set([...arr1,...arr2]))
	}
	{
		
		let arr1 = [1,2,3,4,5,6,5,4,3,2,1];
		let arr2 = [4,5,6,7,8,9,8,7,6,5,4];
		// 求arr2相较于arr1的差集
		console.log(new Set(arr1.filter(item=>!arr2.includes(item))))
		// 求arr相较于arr2的差集
		console.log(new Set(arr2.filter(item=>!arr1.includes(item))))
	}
</script>
</html>